import { createStore, applyMiddleware } from 'redux'
import rootReducer from './reducers'

import thunk from 'redux-thunk'
// import { composeWithDevTools } from 'redux-devtools-extension'
import { getToken } from '@/utils'

let middlewares
// 判断是否为生产环境
if (process.env.NODE_ENV === 'production') {
  // 生产环境
  middlewares = applyMiddleware(thunk)
} else {
  // 开发环境
  const { composeWithDevTools } = require('redux-devtools-extension')
  middlewares = composeWithDevTools(applyMiddleware(thunk))
}

const initialState = {
  login: getToken(),
}

const store = createStore(rootReducer, initialState, middlewares)
export default store
